package com.heima.schedule.feign;

import com.heima.feign.schedule.IScheduleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.TaskDto;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: Tangguo
 * @Date: 2023-06-16  10:53
 */
@RestController
public class ScheduleClient implements IScheduleClient {

    @Autowired
    private TaskService taskService;
    /**
     * 添加任务
     *
     * @param task 任务对象
     * @return 任务id
     */

    @PostMapping("/api/v1/task/add")
    public ResponseResult addTask(@RequestBody TaskDto task) {
        return ResponseResult.okResult(taskService.addTask(task));
    }

    /**
     * 按照类型和优先级来拉取任务
     *
     * @param type
     * @param priority
     * @return
     */
    @Override
    @GetMapping("/api/v1/task/poll/{type}/{priority}")
    public ResponseResult poll(@PathVariable("type") int type, @PathVariable("priority") int priority)  {
        return ResponseResult.okResult(taskService.popTask(type,priority));
    }
}
